﻿
using LPP.Core.Services;
using LPP.Entity.Logs;
using Microsoft.AspNetCore.Mvc;

namespace LPP.API.Controllers.LogsController
{
    [Route("api/[controller]")]
    [ApiController]
    public class LogsController : ControllerBase
    {
        private readonly ILogService _logService;

        public LogsController(ILogService logService)
        {
            _logService = logService;
        }

        [HttpPost]
        public async Task<IActionResult> AddLog([FromBody] Logs log)
        {
            await _logService.AddLogAsync(log.Message, log.Level);
            return CreatedAtAction(nameof(GetLogById), new { id = log.Id }, log);
        }

        [HttpGet]
        public async Task<ActionResult<List<Logs>>> GetAllLogs()
        {
            return Ok(await _logService.GetAllLogsAsync());
        }

        [HttpGet("{id}")]
        public async Task<ActionResult<Logs>> GetLogById(int id)
        {
            var log = await _logService.GetLogByIdAsync(id);
            if (log == null)
            {
                return NotFound();
            }
            return Ok(log);
        }
    }
}
